#!/usr/bin/env bash
committext="提交demo"
downdir="filedownloads"
cd /var/local
if [ ! -d $downdir ];then
  mkdir $downdir 
  else
  echo "文件夹已经存在"
fi
cd $downdir
git init
git pull  git@github.com:demo2099/jscool.git
git remote add upstream git@github.com:demo2099/jscool.git
git fetch upstream
 
arraydir=("yichahucha" "demo2099" "NobyDa" "Meeta" "NavePnow" "Neurogram-R" "chavyleung" "sazs34" "langkhach" "onewayticket255"  "Choler" "Peng-YM" "zZPiglet" "Sunert" "lxk0301" "evilbutcher" "lowking")
arraygit=("https://github.com/yichahucha/surge.git" "https://github.com/demo2099/QTXScripts.git" "https://github.com/NobyDa/Script.git"
        "https://github.com/MeetaGit/MeetaRules.git"  "https://github.com/NavePnow/Profiles.git" "https://github.com/Neurogram-R/Surge.git"
        "https://github.com/chavyleung/scripts.git" "https://github.com/sazs34/TaskConfig.git" "https://github.com/langkhach270389/Scripting.git"
        "https://github.com/onewayticket255/Surge-Script.git" "https://github.com/Choler/Surge.git" "https://github.com/Peng-YM/QuanX.git" 
        "https://github.com/zZPiglet/Task.git" "https://github.com/Sunert/Scripts.git" "https://github.com/lxk0301/scripts.git" 
		"https://github.com/evilbutcher/Quantumult_X.git" "https://github.com/lowking/Scripts.git")

for(( i=0;i<${#arraydir[@]};i++)) do
#${#array[@]}获取数组长度用于循环
	for(( j=0;j<${#arraygit[@]};j++)) do
	if [ $i = $j ];then
	rm -rf ${arraydir[i]}
	mkdir ${arraydir[i]}
	cd ${arraydir[i]}
	git init
	git pull  ${arraygit[j]} master
	#git remote add upstream ${arraygit[j]}
	#git fetch upstream
	#git merge upstream/master
	#echo $committext
	committext=$(git log -1 --pretty=format:'%s' --abbrev-commit| awk -F " " '{print $NF}')
	echo $committext
	rm -rf .git/
	cd ..
	if [ ${arraydir[i]} == 'chavyleung' ];then
		rm -f  /var/local/filedownloads/chavyleung/yarn.lock
	fi
	if [ ${arraydir[i]} == 'lxk0301' ];then
	#	rm -f  /var/local/filedownloads/lxk0301/jd_plantBean.js
	#	rm -f  /var/local/filedownloads/lxk0301/jd_pet.js
	#	rm -f  /var/local/filedownloads/lxk0301/jd_fruit.js

	#	cp  /var/local/jdhelper/jd_fruit.js /var/local/filedownloads/lxk0301/
	#	cp  /var/local/jdhelper/jd_pet.js /var/local/filedownloads/lxk0301/
	#	cp  /var/local/jdhelper/jd_plantBean.js /var/local/filedownloads/lxk0301/

	# sed -i '/您的互助码shareCode/a await $.http.get({url: "http://jdhelper.tk/fruit/"+$.farmInfo.farmUserPro.shareCode}).then((resp) => {jdFruitShareArr=[];jdFruitShareArr.push(resp.body);console.log(`\n【查询jdFruitShareArr】\n`+resp.body);});await shareCodesFormat();' /var/local/filedownloads/lxk0301/jd_fruit.js
	 #  sed -i '/您的互助码shareCode/a await $.http.get({url: "http://jdhelper.tk/pet/"+$.petInfo.shareCode}).then((resp) => {jdPetShareArr=[];jdPetShareArr.push(resp.body);console.log(`\n【查询jdpetShareArr】\n`+resp.body);});await shareCodesFormat();' /var/local/filedownloads/lxk0301/jd_pet.js
	  #   sed -i '/您的互助码plantUuid/a await $.http.get({url: "http://jdhelper.tk/plantbean/"+$.myPlantUuid}).then((resp) => {jdPlantBeanShareArr=resp.body.split(`@`);console.log(`【查询jdBeanShareArr】`+resp.body);});await shareCodesFormat();' /var/local/filedownloads/lxk0301/jd_plantBean.js
  sed -i '/您的互助码shareCode/a await $.http.get({url: "http://jdhelper.tk/fruit/"+$.farmInfo.farmUserPro.shareCode+"?ti="+Date.now()}).then((resp) => {jdFruitShareArr=[];jdFruitShareArr.push(resp.body);console.log(`\n【查询jdFruitShareArr】\n`+resp.body);});await shareCodesFormat();' /var/local/filedownloads/lxk0301/jd_fruit.js
    sed -i '/您的互助码shareCode/a await $.http.get({url: "http://jdhelper.tk/pet/"+$.petInfo.shareCode+"?ti="+Date.now()}).then((resp) => {jdPetShareArr=[];jdPetShareArr.push(resp.body);console.log(`\n【查询jdpetShareArr】\n`+resp.body);});await shareCodesFormat();' /var/local/filedownloads/lxk0301/jd_pet.js
      sed -i '/您的互助码plantUuid/a await $.http.get({url: "http://jdhelper.tk/plantbean/"+$.myPlantUuid+"?ti="+Date.now()}).then((resp) => {jdPlantBeanShareArr=resp.body.split(`@`);console.log(`【查询jdBeanShareArr】`+resp.body);});await shareCodesFormat();' /var/local/filedownloads/lxk0301/jd_plantBean.js

		#种豆得豆
		sed -i 's/66j4yt3ebl5ierjljoszp7e4izzbzaqhi5k2unz2afwlyqsgnasq/fnfkmp5hx2byrqss7h5jr5j2wtnlfimruj4z7ii/g' /var/local/filedownloads/lxk0301/jd_plantBean.js
		sed -i 's/olmijoxgmjutyrsovl2xalt2tbtfmg6sqldcb3q/4oupleiwuds2ar2uqnvnqehopyndwvjwa2qweri/g' /var/local/filedownloads/lxk0301/jd_plantBean.js
		#京东萌宠
		sed -i 's/MTAxODc2NTEzNTAwMDAwMDAwMjg3MDg2MA==/MTAxODc2NTEzMDAwMDAwMDAyNzIzNDI4OQ==/g' /var/local/filedownloads/lxk0301/jd_pet.js
		sed -i 's/MTAxODc2NTEzMzAwMDAwMDAyNzUwMDA4MQ==/MTAxODc2NTEzNDAwMDAwMDAyODczNTY0Nw==/g' /var/local/filedownloads/lxk0301/jd_pet.js
		#京东农场
		sed -i 's/0a74407df5df4fa99672a037eec61f7e/760517d4be0b4082a5c6cf5529e4599e/g' /var/local/filedownloads/lxk0301/jd_fruit.js
		sed -i 's/dbb21614667246fabcfd9685b6f448f3/e349d895905940b59e5bda7d05506f88/g' /var/local/filedownloads/lxk0301/jd_fruit.js
		#摇钱树提示太多
		sed -i 's/^const Notice.*/const Notice =1000;/g' /var/local/filedownloads/lxk0301/jd_moneyTree.js
		#京小超默认兑换
		sed -i 's/^const coinToBeans =.*/const coinToBeans =20;/g' /var/local/filedownloads/lxk0301/jd_blueCoin.js
	fi
	git add -A .
	git commit -m  $committext
	git fetch upstream
	git merge --no-ff -m $committext upstream/master
	git push upstream master
	echo ${array[i]};
	fi
	done;
done;
arraydir=("Absinthe" "faker2")
arraygit=("https://github.com/gys619/Absinthe.git" "https://github.com/shufflewzc/faker2.git")

for(( i=0;i<${#arraydir[@]};i++)) do
#${#array[@]}获取数组长度用于循环
	for(( j=0;j<${#arraygit[@]};j++)) do
	if [ $i = $j ];then
	rm -rf ${arraydir[i]}
	mkdir ${arraydir[i]}
	cd ${arraydir[i]}
	git init
	git pull  ${arraygit[j]} main
	#git remote add upstream ${arraygit[j]}
	#git fetch upstream
	#git merge upstream/main
	#echo $committext
	committext=$(git log -1 --pretty=format:'%s' --abbrev-commit| awk -F " " '{print $NF}')
	echo $committext
	rm -rf .git/
	cd ..
	git add -A .
	git commit -m  $committext
	git fetch upstream
	git merge --no-ff -m $committext upstream/master
	git push upstream master
	echo ${array[i]};
	fi
	done;
done;
cd /var/local/filedownloads
#rm -rf Task
#rm -rf Script
#rm -rf nzw9314
#mkdir nzw9314
#cd nzw9314
#git init
#git pull  https://github.com/nzw9314/QuantumultX.git master
#cp -r Task /var/local/filedownloads
#cp -r Script /var/local/filedownloads
#cd ..
#rm -rf nzw9314
#git add -A .
#git commit -m  "updateScriptOrTask"
git fetch upstream
git merge --no-ff -m "updateScriptOrTask" upstream/master
git push upstream master

git log -50 --name-only --oneline   --pretty=format:"  %cr %s" --graph  > /var/local/gitlog
#echo '' > /var/mail/root